package thread;

public class Demo5_join {
    private static int cnt = 0;
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            for(int i = 0; i < 50000; i++){
                synchronized (locker){
                    cnt++;
                }
//                try {
//                    Thread.sleep(0);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }

            }
        });
        Thread t2 = new Thread(()->{
            for(int i = 0; i < 50000; i++){
                synchronized (locker){
                    cnt++;
                }
//                try {
//                    Thread.sleep(0);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println("total:" + cnt);
    }
}
